<template>
  <!-- hidden PageHeaderWrapper title demo -->
  <page-header-wrapper :title="false">
    <a-card :body-style="{ padding: '24px 32px' }" :bordered="false">
      <a-form @submit="handleSubmit" :form="form" :label-col="labelCol">
        <a-form-item label="id" v-show="false">
          <a-input v-decorator="['id']" name="id" />
        </a-form-item>
        <a-form-item label="" :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }" style="margin: 0; padding: 0">
          <a-checkbox v-model="data.stockingOrder"> 调库订单自动审核 </a-checkbox>
        </a-form-item>
        <a-form-item
          style="margin: 0; padding: 0"
          label=""
          :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
          :wrapperCol="{ lg: { span: 10 }, sm: { span: 17 } }"
        >
          <a-checkbox v-model="data.retailOrder"> 零售订单自动审核 </a-checkbox>
        </a-form-item>
        <a-form-item
          style="margin: 0; padding: 0"
          label=""
          :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
          :wrapperCol="{ lg: { span: 10 }, sm: { span: 17 } }"
        >
          <a-checkbox v-model="data.wholesaleOrder"> 批发订单自动审核 </a-checkbox>
        </a-form-item>
        <a-form-item
          style="margin: 0; padding: 0"
          label=""
          :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
          :wrapperCol="{ lg: { span: 10 }, sm: { span: 17 } }"
        >
          <a-checkbox v-model="data.inOutOrder"> 出入库订单自动审核 </a-checkbox>
        </a-form-item>
        <a-form-item
          label=""
          style="margin: 0; padding: 0"
          :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
          :wrapperCol="{ lg: { span: 10 }, sm: { span: 17 } }"
        >
          <a-checkbox v-model="data.incomeExpensesOrder"> 收支订单自动审核 </a-checkbox>
        </a-form-item>
        <a-form-item
          style="margin: 0; padding: 0"
          label=""
          :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
          :wrapperCol="{ lg: { span: 10 }, sm: { span: 17 } }"
        >
          <a-checkbox v-model="data.financialOrder"> 财务订单自动审核 </a-checkbox>
        </a-form-item>
        <a-form-item
          label=""
          style="margin: 0; padding: 0; display: flex"
          :labelCol="{ lg: { span: 7 }, sm: { span: 7 } }"
          :wrapperCol="{ lg: { span: 10 }, sm: { span: 17 } }"
        >
          <a-checkbox v-model="data.type"> 回收出库订单自动审核 </a-checkbox>
        </a-form-item>
        <a-form-item label="审核人">
          <a-select placeholder="请选择审核人" style="width: 300px" v-decorator="['checker']">
            <a-select-option :value="i.id" v-for="i in option" :key="i.value">{{ i.userName }}</a-select-option>
          </a-select>
        </a-form-item>
        <!-- <div style="display:flex;align-items: center;">
          <span style="width:100px"></span>
          
        </div> -->
        <a-form-item :wrapperCol="{ span: 24 }" style="text-align: center">
          <a-button htmlType="submit" type="primary" icon="check">提交</a-button>
          <!-- <a-button style="margin-left: 8px">{{ $t('form.basic-form.form.save') }}</a-button> -->
        </a-form-item>
      </a-form>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { getEmployeesListUsingPOST } from '@/api/api/yuangongguanli.ts'
import { updateAutoCheckSettingUsingPOST, getAutoCheckSettingUsingGET } from '@/api/api/xitongguanli.ts'
import pick from 'lodash.pick'
const fields = [
  'stockingOrder',
  'retailOrder',
  'wholesaleOrder',
  'inOutOrder',
  'incomeExpensesOrder',
  'financialOrder',
  'type',
  'checker',
  'id'
]
export default {
  name: 'AutoReview',
  data() {
    return {
      value: [],
      form: this.$form.createForm(this),
      option: [],
      labelCol: { span: 1 },
      data: {
        stockingOrder: false,
        retailOrder: false,
        wholesaleOrder: false,
        inOutOrder: false,
        incomeExpensesOrder: false,
        financialOrder: false,
        type: false,
      },
      optionParam: {
        pageNo: 1,
        pageSize: 999,
        queryCondition: '',
        status: 1,
      },
    }
  },
  mounted() {
    this.getOption()
    this.getDetail()
  },
  methods: {
    getDetail() {
      getAutoCheckSettingUsingGET(this.queryParam)
        .then((res) => {
          const val = {
            stockingOrder: res.data.stockingOrder === '1' ? true : false,
            retailOrder: res.data.retailOrder === '1' ? true : false,
            wholesaleOrder: res.data.wholesaleOrder === '1' ? true : false,
            inOutOrder: res.data.inOutOrder === '1' ? true : false,
            incomeExpensesOrder: res.data.incomeExpensesOrder === '1' ? true : false,
            financialOrder: res.data.financialOrder === '1' ? true : false,
            type: res.data.type === '1' ? true : false,
          }
          this.data = val
          this.form.setFieldsValue(pick(res.data, fields))
        })
        .catch((error) => {
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
    },
    getOption() {
      getEmployeesListUsingPOST(this.optionParam)
        .then((res) => {
          this.option = res.data.list
        })
        .catch((error) => {
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
    },
    // handler
    handleSubmit(e) {
      e.preventDefault()
      this.form.validateFields((err, values) => {
        if (!err) {
          const val = {
            stockingOrder: this.data.stockingOrder === true ? '1' : '0',
            retailOrder: this.data.retailOrder === true ? '1' : '0',
            wholesaleOrder: this.data.wholesaleOrder === true ? '1' : '0',
            inOutOrder: this.data.inOutOrder === true ? '1' : '0',
            incomeExpensesOrder: this.data.incomeExpensesOrder === true ? '1' : '0',
            financialOrder: this.data.financialOrder === true ? '1' : '0',
            type: this.data.type === true ? '1' : '0',
          }
          updateAutoCheckSettingUsingPOST({ ...values, ...val })
            .then((res) => {
              this.$message.success('操作成功')
            })
            .catch(() => {
              this.$message.error('设置失败,请联系管理员!')
            })
        }
      })
    },
  },
}
</script>
